home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14666 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  70 lines

  1. Newsgroups: comp.object,comp.lang.c++,comp.lang.java
  2. Path: newsfeed.acns.nwu.edu!ftpbox!mothost!schbbs!news
  3. From: shang@corp.mot.com (David L. Shang)
  4. Subject: Re: Java: What's the Big Deal?
  5. Reply-To: shang@corp.mot.com
  6. Organization: MOTOROLA 
  7. Date: Mon, 1 Apr 1996 15:54:16 GMT
  8. Message-ID: <1996Apr1.155416.12816@schbbs.mot.com>
  9. References: <4jk4ee$7ri@newsbf02.news.aol.com>
  10. Sender: news@schbbs.mot.com (SCHBBS News Account)
  11. Nntp-Posting-Host: 129.188.128.126
  12.  
  13. In article <4jk4ee$7ri@newsbf02.news.aol.com> youngbros@aol.com (YoungBros)  
  14. writes:
  15. > I am not sure if Java gc really work.  Some of my applets exhaust memory
  16. > after running for a while.  I remember reading that the 'finalize' method
  17. > is not guaranteed to be called.  If so, then we can't avoid memory leak. 
  18. > Am I wrong?
  19.  
  20. The more a program depends on GC, the more likely it will exhaust memory;
  21. because the storage is collected only when all its references are
  22. no longer valid, not at the time when all its references are no longer
  23. used. Be careful, never make a variable's lifetime unecessarily longer
  24. than the required.
  25.  
  26. The more a language depends on GC, the more likely its application will
  27. exhaust memory, or at the best, will make the operating system busy
  28. to crunch the memory. GC is not always required. For example:
  29.  
  30.     class point
  31.     {
  32.        public:
  33.         float x;
  34.         float y;
  35.         float z;
  36.     };
  37.     class FaceSet
  38.     {
  39.         coordIndex point[];
  40.         ...
  41.        public:        
  42.         loadCoordIndex (char* file_name)
  43.         {
  44.             one million of points read here, and
  45.             coordIndex is created as an array of
  46.             a million of points.
  47.         };
  48.     };
  49.  
  50. With Java's array, memory will be smashed into millions of small
  51. pieces. Here is a brief comparison:
  52.  
  53.         Java array            C++ array
  54.  
  55. pieces:        1,000,000 pieces        1 piece
  56.  
  57. expence:    1,000,000 type refs +        3,000,000 floats
  58.         1,000,000 obj refs +
  59.         1,000,000 gc overheads +
  60.         3,000,000 floats
  61.  
  62. allocation:    1,000,001 times            1 time
  63.  
  64. free time:    1,000,001 times            1 time
  65.  
  66.  
  67. David Shang
  68.  
  69.